from django.http import HttpResponse
from captcha.image import ImageCaptcha
import string
import random
import redis


# 生成图片验证码
def gen_image_code(request, uuid_):
    # 生成随机字符串
    code_str = "".join(random.sample(string.ascii_letters + string.digits, 4))
    print("字符码:", code_str)

    # 存储随机字符串
    redis_conn = redis.Redis(host="localhost", port=6379, db=0, password='laufing')
    key = "imageCode:%s"%uuid_
    redis_conn.set(key, code_str, ex=300)
    redis_conn.close()

    # 图片验证码
    captcha_obj = ImageCaptcha()
    image_captcha = captcha_obj.generate(code_str)  # BytesIO对象， 类似于文件对象

    print(image_captcha)


    return HttpResponse(image_captcha, content_type="image/png")

<<<<<<< HEAD
from rest_framework_jwt.views import APIView
class Lauf(APIView):
    def get(self, request):
        print("rest_jwt")
        return HttpResponse("rest_jwt")

def rest(request):
    print("rest")
    return HttpResponse("rest")
=======

def upload(request):

    if request.method == "POST":
        print("xxxx", request.POST)

        return HttpResponse("上传成功")
>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9
